from pydantic import BaseModel, field_validator


class Message(BaseModel):
    """
    Message 单条聊天消息
    """
    role: str
    content: str

    @field_validator("role")
    @classmethod
    def validate_role(cls,value:str) -> str:
        allowed_roles = ["user","assistant","system"]
        if value not in allowed_roles:
            raise ValueError(f"role 值必须是以下之一{allowed_roles}")
        return value

    @field_validator('content')
    @classmethod
    def validate_content(cls,value: str) -> str:
        if(len(value.strip()) == 0):
            raise ValueError("content 不能为空")
        return value